﻿import QtQuick 2.0

Rectangle {
    id: root

    height: parent.height; width: parent.width

    property var tableData: [[1,2,3,4,5,6],[1,2,3,4,5,6]]

    onVisibleChanged: {
        if(visible){
            tableData = []
            var codeList = CBarCode.getBarCodeList()
            for(let i = 0; i < codeList.length; i ++){
                tableData.push([])
                tableData[i].push(i)
                tableData[i].push(codeList[i]["CreateDate"])
                tableData[i].push(codeList[i]["Code"])
                tableData[i].push(codeList[i]["State"])
                tableData[i].push(codeList[i]["Times"])
                tableData[i].push("删除")
            }
            tableDataChanged()
        }
    }

    property real lineHeight: 50*dp

    radius: 5*dp

    color: "#F7F7F7"

    Text{
        x: 20*dp; y: 20*dp
        text: "耗材编码统计"
        font.pixelSize: config.fontsize + 3*dp
        font.bold: true
    }

    Row{
        height: 40*dp
        width: 300*dp

    }

    Rectangle{
        x: 20*dp; y: 70*dp
        height: parent.height - 90*dp; width: parent.width - 2*x
        // 这是一个表格
        Item{
            id: table
            property var title: ["序号", "录入时间", "耗材编码", "状态", "次数", "操作"]
            property var tableScale: [0.15, 0.2, 0.2, 0.15, 0.15, 0.15]
            x: 20*dp; y: 20*dp
            height: parent.height - 2*y; width: parent.width - 2*x
            // 表身
            ListView{
                y: lineHeight
                height: parent.height - lineHeight; width: table.width
                clip: true
                model: tableData.length
                delegate: Rectangle{
                    id: lineItem
                    height: lineHeight; width: table.width
                    property int lineIdx: index
                    Row{
                        height: lineHeight; width: table.width
                        Repeater{
                            model: tableData[lineItem.lineIdx].length
                            Item{
                                height: lineHeight; width: table.tableScale[index] * table.width
                                Text{
                                    anchors.centerIn: parent
                                    text: tableData[lineItem.lineIdx][index]
                                    font.pixelSize: config.fontsize
                                }
                            }
                        }
                    }
                    Rectangle{
                        height: 1; width: parent.width
                        color: "#EBEDF0"
                        y: parent.height - height
                    }
                }
            }

            // 表头
            Rectangle{
                height: lineHeight; width: parent.width
                color: "#F7F8FA"
                border.color: "#EBEDF0"
                Row{
                    anchors.fill: parent
                    Repeater{
                        model: table.title.length
                        anchors.fill: parent
                        Item{
                            height: lineHeight; width: parent.width * table.tableScale[index]
                            Text{
                                anchors.centerIn: parent
                                text: table.title[index]
                                font.pixelSize: config.fontsize
                                font.bold: true
                            }
                        }
                    }
                }
            }
        }
    }

}
